using namespace std;
//
#include<iostream> 
#include<fstream>
#include<gsl/gsl_rng.h>
#include<math.h>
#include"flysim.h"

//********* cList member functions

cListElement::cListElement():cFlySim()
{
  dStats = new float[ciNoStats];
  // initialize the stats
  for (int i=0; i<ciNoStats;i++) {
    this->dStats[i]=0;
  }
  //cerr<<"Constructed dStats\n";
}

// copy constructor

cListElement::cListElement(const cListElement & listElement){
  //cerr<<"Calling copy constructor\n";
  dStats = new float[ciNoStats];
  for (int i=0; i<ciNoStats;i++){
    this->dStats[i]=listElement.dStats[i];
  }
  //cerr<<"Copied from old dStats\n";
}

cListElement::~cListElement(){
  delete[] dStats;
  //cerr<<"Deleted dStats\n";
}

void cListElement::Print()
{
	std::cout<<"\n"<<this<<" "<<pPrev<<" "<<pNext<<":  ";
	for (int i=0;i<ciNoStats;i++)
		std::cout<<dStats[i]<<" ";
}


cListElement* cLinkedList::GetAnElement()
{
	cListElement *pNewLE;
	if (pTopOfPileOfSpareListElements!=&BottomOfPileOfSpareListElements)
	{
		// We have some spare list elements - go get one
		pNewLE=pTopOfPileOfSpareListElements;
		pTopOfPileOfSpareListElements=pTopOfPileOfSpareListElements->pPrev;
		pNewLE->pPrev=NULL;
		pNewLE->pNext=NULL;
		pTopOfPileOfSpareListElements->pNext=NULL;
	}
	else
	{
		// we have run out of spares - make a new one
		pNewLE= new cListElement;
	}
	return pNewLE;
}





void cListElement::ListWrite()
{
	ofile <<"\n"<<this<<" "<<pPrev<<" "<<pNext<<":  ";
	for (int i=0;i<ciNoStats;i++)
		ofile <<dStats[i]<<" ";
}

